package com.liyi.dao;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;

import com.zero.basic.dao.DefaultBaseDao;
import com.zero.basic.dao.SqlListBaseDao;
import com.zero.basic.dao.SqlQueryBaseDao;
import com.zero.basic.exception.SmsDaoException;
import com.zero.mms.model.Employee;

@Repository("empDaoLiyi")
public class EmpDaoImpl extends DefaultBaseDao<Employee> implements EmpDao {

	@Inject
	private SqlListBaseDao<?> sqlListBaseDao;
	@Inject 
	private SqlQueryBaseDao<?> sqlQueryBaseDao;
	
	/* 获取某 [部门] 所有 [员工] 的id */
	@Override
	public List<Integer> getEmpIdsByDepIds(String allDepIds) throws SmsDaoException {
		try {
			String sql = "select e.emp_id from t_emp e where e.dep_id in (" + allDepIds + ")";
			List<Integer> ids = sqlListBaseDao.listBySql(sql, null, null, false, false);
			return ids;
		} catch (Exception e) {
			throw new SmsDaoException();
		}
	}
	
	/* 根据 [员工]id 获得 [员工]姓名 */
	@Override
	public String getEmpNameByEmpId(Integer empId) throws SmsDaoException {
		try {
			String sql = "select e.emp_name from t_emp e where e.emp_id = " + empId;
			String empName = (String) sqlQueryBaseDao.queryBySql(sql, null, null, false, false);
			return empName;
		} catch (Exception e) {
			throw new SmsDaoException();
		}
	}
	
	/* 根据 [部门]id 获取 [员工]列表 */
	@Override
	public List<Employee> getEmpsByDepId(String allDepIds) throws SmsDaoException {
		try {
			String sql = "select e.* from t_emp e where e.dep_id in (" + allDepIds + ")";
			List<Employee> emps = sqlListBaseDao.listBySql(sql, null, Employee.class, true, true);
			return emps;
		} catch (Exception e) {
			throw new SmsDaoException();
		}
	}

}
